package com.qst.pojo.vo;

import com.qst.pojo.entity.Order;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单视图对象
 */
@Data
public class OrderVO {
    private Integer id;
    private String orderNo;
    private Integer customerId;
    private String customerName;
    private String customerPhone;
    private Integer stationId;
    private String stationName;
    private String pickupAddress;
    private LocalDateTime pickupTime;
    private LocalDateTime actualPickupTime;
    private BigDecimal totalAmount;
    private BigDecimal totalWeight;
    private String status;
    private String notes;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    private LocalDateTime confirmedAt;
    private LocalDateTime startedAt;
    private LocalDateTime completedAt;
    
    // 订单项列表
    private List<OrderItemVO> items = new ArrayList<>();
    
    /**
     * 从Order实体转换为VO
     */
    public static OrderVO fromEntity(Order order) {
        OrderVO vo = new OrderVO();
        vo.setId(order.getId());
        vo.setOrderNo(order.getOrderNo());
        vo.setCustomerId(order.getCustomerId());
        vo.setStationId(order.getStationId());
        vo.setPickupAddress(order.getPickupAddress());
        vo.setPickupTime(order.getPickupTime());
        vo.setActualPickupTime(order.getActualPickupTime());
        vo.setTotalAmount(order.getTotalAmount());
        vo.setTotalWeight(order.getTotalWeight());
        vo.setStatus(order.getStatus() != null ? order.getStatus().name() : null);
        vo.setNotes(order.getNotes());
        vo.setCreatedAt(order.getCreatedAt());
        vo.setUpdatedAt(order.getUpdatedAt());
        vo.setConfirmedAt(order.getConfirmedAt());
        vo.setStartedAt(order.getStartedAt());
        vo.setCompletedAt(order.getCompletedAt());
        
        // 设置客户信息
        if (order.getCustomer() != null) {
            vo.setCustomerName(order.getCustomer().getRealName());
            vo.setCustomerPhone(order.getCustomer().getPhone());
        }
        
        // 设置站点信息
        if (order.getStation() != null) {
            vo.setStationName(order.getStation().getName());
        }
        
        return vo;
    }
}

